package pit.com.ordermobilesystem.provider;
import pit.com.ordermobilesystem.model.Category;
import pit.com.ordermobilesystem.model.Description;
import pit.com.ordermobilesystem.model.Item;
import pit.com.ordermobilesystem.model.Order;
import pit.com.ordermobilesystem.model.OrderItem;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.provider.BaseColumns;

	
	public class OrderMobileProvider extends ContentProvider {	
		private static final String DATABASE_NAME = "OrderMobileProvider.db";
		private static final int DATABASE_VERSION = 9;
		private static final String TABLE_CATEGORY = "category";
		public static final String TABLE_DESCRIPTION ="description";
		public static final String TABLE_ITEM ="item";
		public static final String TABLE_ORDER_ITEM="orderitem";
		public static final String TABLE_ORDER="ordermobile";

		
		public static final String AUTHORITY ="pit.com.ordermobilesystem.provider.OrderMobileProvider";
		public static final Uri CATEGORY_CONTENT_URI =Uri.parse("content://"+AUTHORITY + "/"+TABLE_CATEGORY);
		public static final Uri DESCRIPTION_CONTENT_URI = Uri.parse("content://" +AUTHORITY+"/"+TABLE_DESCRIPTION);
		public static final Uri ITEM_CONTENT_URI = Uri.parse("content://" +AUTHORITY+"/"+TABLE_ITEM);
		public static final Uri ORDER_ITEM_CONTENT_URI = Uri.parse("content://" +AUTHORITY+"/"+TABLE_ORDER_ITEM);
		public static final Uri ORDER_CONTENT_URI = Uri.parse("content://" +AUTHORITY+"/"+TABLE_ORDER);

		public interface CategoryTable extends BaseColumns{
		public static final String ID_CATEGORY = "Id";
		public static final String NAME_CATEGORY = "NameCategory";
		}
		public interface DescriptionTable extends BaseColumns{
		         public static String ID="Id";
		         public static String ID_ITEM="IdItem";
		         public static String LINK_IMAGE="LinkImage";
		         public static String DESCRIPTION="Description";
		}
		
		public interface ItemTable extends BaseColumns{
	         public static String ID_ITEM="Id";	        
	         public static String NAME_ITEM="NameItem";
	         public static String ID_CATEGORY="IdCategory";
	         public static String PRICE="Price";
	         public static String DESCRIPTION="Description";
	         public static String LINK_IMAGE="LinkImage";
	         public static String DISCOUNT="Discount";
		}
		
	    public interface Order_ItemTable extends BaseColumns{
	         public static String ID_ORDER="IdOrder";
	         public static String ID_ITEM="IdItem";
	         public static String PRICE="Price";
	         public static String NAME_ITEM="NameItem";
	         public static String SUM_ITEM="SumItem";
	         public static String DISCOUNT="Discount";
	    }
	    public interface OrderTable extends BaseColumns{
	         public static String ID_ORDER="IdOrder";
	         public static String NAME_ORDER="NameOrder";
	         public static String NAME_CUSTOMER="NameCustomer";
	         public static String MOBILE_CUSTOMER="MobileCustomer";
	         public static String DATE_ORDER="DateOrder";
	         public static String DISCOUNT="Discount";
	         public static String SUM_PRICE="SumPrice";
	         public static String DESCRIPTION="Description";
	    }
		/* it is */
		public static ContentValues getcontentValuesCategory(Category category){
			ContentValues values = new ContentValues();
			values.put(CategoryTable.ID_CATEGORY, category.getId());
			values.put(CategoryTable.NAME_CATEGORY, category.getNameCategory());
			return values;
		}
	    public static ContentValues getContentValuesDescription (Description description) {
            ContentValues values = new ContentValues();
            values.put(DescriptionTable.ID,description.getId());
            values.put(DescriptionTable.ID_ITEM,description.getIdItem());
            values.put(DescriptionTable.LINK_IMAGE,description.getLinkImage());
            values.put(DescriptionTable.DESCRIPTION,description.getDescription());
            return values;
	    }
	    public static ContentValues getContentValuesItem(Item item) {
            ContentValues values = new ContentValues();
            values.put(ItemTable.ID_ITEM,item.getId());
            values.put(ItemTable.ID_CATEGORY,item.getIdCategory());
            values.put(ItemTable.NAME_ITEM,item.getNameItem());
            values.put(ItemTable.PRICE,item.getPrice());
            values.put(ItemTable.DESCRIPTION,item.getDescription());
            values.put(ItemTable.LINK_IMAGE,item.getLinkImage());
            values.put(ItemTable.DISCOUNT,item.getDiscount());
            return values;
	    }
	    public static ContentValues getContentValuesOrder_Item(OrderItem order_item) {
            ContentValues values = new ContentValues();
            values.put(Order_ItemTable.ID_ORDER,order_item.getIdOrder());
            values.put(Order_ItemTable.ID_ITEM,order_item.getIdItem());
            values.put(Order_ItemTable.PRICE,order_item.getPrice());
            values.put(Order_ItemTable.NAME_ITEM,order_item.getNameItem());
            values.put(Order_ItemTable.SUM_ITEM,order_item.getNumberItem());
            values.put(Order_ItemTable.DISCOUNT,order_item.getDiscount());
            return values;
	    }	    
	   public static ContentValues getContentValuesOrder(Order order) {
		   ContentValues values = new ContentValues();
		   values.put(OrderTable.ID_ORDER,order.getIdOrder());
		   values.put(OrderTable.NAME_ORDER,order.getNameOrder());
		   values.put(OrderTable.NAME_CUSTOMER,order.getNameCustomer());
		   values.put(OrderTable.MOBILE_CUSTOMER,order.getMobileCustomer());
		   values.put(OrderTable.DATE_ORDER,order.getDateOrder());
		   values.put(OrderTable.DISCOUNT,order.getDiscount());
		   values.put(OrderTable.SUM_PRICE,order.getSumPrice());
		   values.put(OrderTable.DESCRIPTION,order.getDescription());
		   return values;
	   }
	    /* it is */
		public static void getCategory(Cursor cursor, Category category){
			category.setId(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.CategoryTable.ID_CATEGORY)));
			category.setNameCategory(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.CategoryTable.NAME_CATEGORY)));
		}
		
		public static void getDescription(Cursor cursor,Description description) {
	        description.setId(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.DescriptionTable.ID)));
	        description.setIdItem(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.DescriptionTable.ID_ITEM)));
	        description.setLinkImage(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.DescriptionTable.LINK_IMAGE)));
	        description.setDescription(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.DescriptionTable.DESCRIPTION)));
	    }
	    public static void getItem(Cursor cursor,Item item) {
	        item.setId(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.ItemTable.ID_ITEM)));
	        item.setIdCategory(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.ItemTable.ID_CATEGORY)));
	        item.setNameItem(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.ItemTable.NAME_ITEM)));
	        item.setPrice(cursor.getDouble(cursor.getColumnIndex(OrderMobileProvider.ItemTable.PRICE)));
	        item.setDescription(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.ItemTable.DESCRIPTION)));
	        item.setLinkImage(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.ItemTable.LINK_IMAGE)));
	        item.setDiscount(cursor.getDouble(cursor.getColumnIndex(OrderMobileProvider.ItemTable.DISCOUNT)));
	    }
	    public static void getOrder_Item(Cursor cursor,OrderItem order_item) {
	        order_item.setIdOrder(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.Order_ItemTable.ID_ORDER)));
	        order_item.setIdItem(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.Order_ItemTable.ID_ITEM)));
	        order_item.setPrice(cursor.getDouble(cursor.getColumnIndex(OrderMobileProvider.Order_ItemTable.PRICE)));
	        order_item.setNameItem(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.Order_ItemTable.NAME_ITEM)));
	        order_item.setNumberItem(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.Order_ItemTable.SUM_ITEM)));
	        order_item.setDiscount(cursor.getDouble(cursor.getColumnIndex(OrderMobileProvider.Order_ItemTable.DISCOUNT)));
	    }
	    public static void getOrder(Cursor cursor,Order order) {
	        order.setIdOrder(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.OrderTable.ID_ORDER)));
	        order.setNameOrder(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.OrderTable.NAME_ORDER)));
	        order.setNameCustomer(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.OrderTable.NAME_CUSTOMER)));
	        order.setMobileCustomer(cursor.getInt(cursor.getColumnIndex(OrderMobileProvider.OrderTable.MOBILE_CUSTOMER)));
	        //data value getLong , i don't 
	        order.setDateOrder(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.OrderTable.DATE_ORDER)));
	        order.setDiscount(cursor.getDouble(cursor.getColumnIndex(OrderMobileProvider.OrderTable.DISCOUNT)));
	        order.setSumPrice(cursor.getDouble(cursor.getColumnIndex(OrderMobileProvider.OrderTable.SUM_PRICE)));
	        order.setDescription(cursor.getString(cursor.getColumnIndex(OrderMobileProvider.OrderTable.DESCRIPTION)));
	    }	  
		
		/* it is */
		public static final int CATEGORY_BASE = 0;
		public static final int CATEGORY = CATEGORY_BASE;
		public static final int CATEGORY_ID = CATEGORY_BASE+1;
		
		private static final int DESCRIPTION_BASE = 5;
	    private static final int DESCRIPTION = DESCRIPTION_BASE;
	    private static final int DESCRIPTION_ID = DESCRIPTION_BASE+1;
		
	    private static final int ITEM_BASE = 10;
	    private static final int ITEM = ITEM_BASE;
	    private static final int ITEM_ID = ITEM_BASE+1;

	    private static final int ORDER_ITEM_BASE = 15;
	    private static final int ORDER_ITEM = ORDER_ITEM_BASE;
	    private static final int ORDER_ITEM_ID = ORDER_ITEM_BASE+1;	    
	    
	    private static final int ORDER_BASE = 20;
	    private static final int ORDER = ORDER_BASE;
	    private static final int ORDER_ID = ORDER_BASE+1;	    
		/* it is */
		public static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
		static{
			final UriMatcher matcher = sURIMatcher;
			matcher.addURI(AUTHORITY,TABLE_CATEGORY, CATEGORY);
			matcher.addURI(AUTHORITY, TABLE_CATEGORY+"/#", CATEGORY_ID);
			
			matcher.addURI(AUTHORITY, TABLE_DESCRIPTION, DESCRIPTION);
	        matcher.addURI(AUTHORITY,TABLE_DESCRIPTION + "/#", DESCRIPTION_ID);
	        
	        matcher.addURI(AUTHORITY, TABLE_ITEM, ITEM);
	        matcher.addURI(AUTHORITY,TABLE_ITEM + "/#", ITEM_ID);
	        
	        matcher.addURI(AUTHORITY, TABLE_ORDER_ITEM, ORDER_ITEM);
	        matcher.addURI(AUTHORITY,TABLE_ORDER_ITEM + "/#", ORDER_ITEM_ID);
	             
	        matcher.addURI(AUTHORITY, TABLE_ORDER, ORDER);
	        matcher.addURI(AUTHORITY,TABLE_ORDER + "/#", ORDER_ID);
		}
		
		//Using SQLiteDatabase to store all content provider data
	
	    private SQLiteDatabase mDatabase;
	
	    @SuppressWarnings("deprecation")
		public synchronized SQLiteDatabase getDatabase(final Context context) {
	        // Always return the cached database, if we've got one
	        if (mDatabase != null) {
	            return mDatabase;
	        }
	
	        final DatabaseHelper helper = new DatabaseHelper(context, DATABASE_NAME);
	        mDatabase = helper.getWritableDatabase();
	        if (mDatabase != null) {
	            mDatabase.setLockingEnabled(true);
	        }
	
	        return mDatabase;
	    }  
		//using DatabaseHelper Class to help manage your database
		private static class DatabaseHelper extends SQLiteOpenHelper
		{
			public DatabaseHelper(Context context, String database_name) {
				super(context, database_name , null, DATABASE_VERSION);
			}
	
			@Override
			public void onCreate(SQLiteDatabase db) {
				String querry ="create table " + TABLE_CATEGORY 
						+ "("+ CategoryTable._ID + " integer primary key autoincrement,"	
						+ CategoryTable.ID_CATEGORY + " integer,"
						+ CategoryTable.NAME_CATEGORY+" text not null);";					
				db.execSQL(querry);
				
				 querry= "create table " + TABLE_DESCRIPTION
					   + "("+ DescriptionTable._ID + " integer primary key autoincrement,"	
					   + DescriptionTable.ID + " integer,"
					   + DescriptionTable.ID_ITEM + " integer,"
					   + DescriptionTable.LINK_IMAGE + " text,"
					   + DescriptionTable.DESCRIPTION +" text);";
					    db.execSQL(querry);
					    
				 querry= "create table " + TABLE_ITEM
						+ "("+ ItemTable._ID + " integer primary key autoincrement,"	
						+ ItemTable.ID_ITEM + " integer,"				    
					    + ItemTable.NAME_ITEM+" text,"
					    + ItemTable.ID_CATEGORY+" integer,"
					    + ItemTable.PRICE+" real,"
					    + ItemTable.DESCRIPTION+" text ,"
					    + ItemTable.LINK_IMAGE+" text ,"
					    + ItemTable.DISCOUNT+" real);";	  
				 db.execSQL(querry);
				 
				 querry= "create table " + TABLE_ORDER 
					 + "("+ OrderTable._ID + " integer primary key autoincrement,"	
					 + OrderTable.ID_ORDER + " integer ,"
					 + OrderTable.NAME_ORDER+" text,"
					 + OrderTable.NAME_CUSTOMER+" text,"
					 + OrderTable.MOBILE_CUSTOMER+" text,"
					 + OrderTable.DATE_ORDER+" text,"
					 + OrderTable.DISCOUNT+" real,"
					 + OrderTable.SUM_PRICE+" real,"
					 + OrderTable.DESCRIPTION+" text);";
				db.execSQL(querry);			
				 
				 querry= "create table " + TABLE_ORDER_ITEM
						+ "("+ Order_ItemTable._ID + " integer primary key autoincrement,"	
						+ Order_ItemTable.ID_ORDER + " integer,"
						+ Order_ItemTable.ID_ITEM+" integer,"
						+ Order_ItemTable.PRICE+" text,"
						+ Order_ItemTable.NAME_ITEM+" text,"
						+ Order_ItemTable.SUM_ITEM+" integer,"
						+ Order_ItemTable.DISCOUNT+" text);";
				 db.execSQL(querry); 
					
						         
			
			}
	
			@Override
			public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
				 
				db.execSQL("DROP TABLE IF EXISTS titles"+TABLE_CATEGORY);
				db.execSQL("DROP TABLE IF EXISTS titles"+TABLE_DESCRIPTION);
				db.execSQL("DROP TABLE IF EXISTS titles"+TABLE_ITEM);
				db.execSQL("DROP TABLE IF EXISTS titles"+TABLE_ORDER_ITEM);
				db.execSQL("DROP TABLE IF EXISTS titles"+TABLE_ORDER);	
				onCreate(db);
			}
		}
		
		
		@Override
		public int delete(Uri uri, String selection, String[] selectionArgs) {
			// TODO Auto-generated method stub
			final int match = sURIMatcher.match(uri);
			final Context context = getContext();
			final SQLiteDatabase db = getDatabase(context);
			int result = -1;
			db.beginTransaction();
			try {
				switch(match){
					case CATEGORY :
						result = db.delete(TABLE_CATEGORY, selection, selectionArgs);
						db.setTransactionSuccessful();
						break;
					case DESCRIPTION:
			            result = db.delete(TABLE_DESCRIPTION, selection, selectionArgs);
			            db.setTransactionSuccessful();break;
					case ITEM:
				            result = db.delete(TABLE_ITEM, selection, selectionArgs);
				            db.setTransactionSuccessful();break;
					case ORDER_ITEM:
			            	result = db.delete(TABLE_ORDER_ITEM, selection, selectionArgs);
			            	db.setTransactionSuccessful();break;        
					case ORDER:
				            result = db.delete(TABLE_ORDER, selection, selectionArgs);
				            db.setTransactionSuccessful();break;        
				   default:
			                throw new IllegalArgumentException("Unknown URI " + uri);
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}finally {
	            db.endTransaction();
	        }	        
	        //after delete ,content provider will notified to        
	        getContext().getContentResolver().notifyChange(uri, null);
			return result;
		}
	
		@Override
		public String getType(Uri uri) {
			// TODO Auto-generated method stub
			return null;
		}
	
		@Override
		public Uri insert(Uri uri, ContentValues values) {
			final int match = sURIMatcher.match(uri);
			
			final Context context = getContext();
			final SQLiteDatabase db = getDatabase(context);
			long id ;
			Uri resultUri =null;
										
				try {
					switch(match){
					case CATEGORY : id = db.insert(TABLE_CATEGORY,null, values);
					 resultUri = ContentUris.withAppendedId(uri,id);
					 break;
					case DESCRIPTION:
						 id = db.insert(TABLE_DESCRIPTION, null, values);
				         resultUri = ContentUris.withAppendedId(uri, id); break;
					case ITEM:
				         id = db.insert(TABLE_ITEM, null, values);
				         resultUri = ContentUris.withAppendedId(uri, id); break; 
					case ORDER_ITEM:
				         id = db.insert(TABLE_ORDER_ITEM, null, values);
				         resultUri = ContentUris.withAppendedId(uri, id); break;     
					case ORDER:
				         id = db.insert(TABLE_ORDER, null, values);
				         resultUri = ContentUris.withAppendedId(uri, id); break;     
					default:
		                throw new IllegalArgumentException("Unknown URI " + uri);
					}
					
				} catch (Exception e) {
					// TODO: handle exception
				}finally {
	
		        }
		        getContext().getContentResolver().notifyChange(uri, null);
		        return  resultUri;
		}
	
		@Override
		public int bulkInsert(final Uri uri, final ContentValues[] values) {

		        final int match = sURIMatcher.match(uri);
		        final Context context = getContext();

		        // Pick the correct database for this operation
		        final SQLiteDatabase db = getDatabase(context);
		        
		        int numberInserted = 0;
		    	
		        db.beginTransaction();
		        try {
		            switch (match) {
		                case CATEGORY:
		                    Category category = new Category();	
		                    for ( ContentValues value : values) {
		                		String sql = "SELECT * FROM "+TABLE_CATEGORY+" WHERE  "+CategoryTable.ID_CATEGORY + "="+value.getAsString(CategoryTable.ID_CATEGORY);
		                		Cursor cursor = db.rawQuery(sql, null);
		                		boolean check=false;
		                		if (cursor.moveToFirst()) {
		                			getCategory(cursor, category);
		                		    check= true;
		                		} else {
		                		    check=false;
		                		}
		                		cursor.close();                    	
		                    	if(check==false){
		                    		db.insert(TABLE_CATEGORY, null, value);
		                    	}else{

		                    		db.update(TABLE_CATEGORY, value,  CategoryTable.ID_CATEGORY+"="+value.getAsString(CategoryTable.ID_CATEGORY), null);
		                    	}
		                    }

		                    db.setTransactionSuccessful();
		                    numberInserted = values.length;
		                    break; 
		                case ITEM:
		                    Item item = new Item();	
		                    for ( ContentValues value : values) {
		                		String sql = "SELECT * FROM "+TABLE_ITEM+" WHERE  "+ItemTable.ID_ITEM + "="+value.getAsString(ItemTable.ID_ITEM);
		                		Cursor cursor = db.rawQuery(sql, null);
		                		boolean check = false;
		                		if (cursor.moveToFirst()) {
		                			getItem(cursor, item);
		                		    check= true;
		                		} else {
		                		    check=false;
		                		}
		                		cursor.close();                    	
		                    	if(check==false){
		                    		db.insert(TABLE_ITEM, null, value);
		                    	}else{

		                    		db.update(TABLE_ITEM, value,  ItemTable.ID_ITEM+"="+value.getAsString(ItemTable.ID_ITEM), null);
		                    	}
		                    }

		                    db.setTransactionSuccessful();
		                    numberInserted = values.length;
		                    break; 
	
		                default:
		                    throw new IllegalArgumentException("Unknown URI " + uri);
		            }
		        }catch (Exception e) {
					e.printStackTrace();
		        	
		        }finally {
		            db.endTransaction();
		        }

		        // Notify with the base uri, not the new uri (nobody is watching a new
		        // record)
		        context.getContentResolver().notifyChange(uri, null);
		        return numberInserted;
		    }	
		
		
		
		@Override
		public boolean onCreate() {
			Context context = getContext();
			DatabaseHelper dbHelper = new DatabaseHelper(context,DATABASE_NAME);
			mDatabase = dbHelper.getWritableDatabase();
			return (mDatabase == null) ? false :true;
		}
	
		@Override
		public Cursor query(Uri uri, String[] projection, String selection,	String[] selectionArgs, String sortOrder) {
			SQLiteQueryBuilder sqlBuilder = new SQLiteQueryBuilder();

			Cursor c = null;
			final int match = sURIMatcher.match(uri);
		  switch(match){
			case CATEGORY: 
				sqlBuilder.setTables(TABLE_CATEGORY);
				c = sqlBuilder.query(mDatabase, projection, selection,selectionArgs, null, null, sortOrder);
				break;
			case DESCRIPTION:
				sqlBuilder.setTables(TABLE_DESCRIPTION);
                c = sqlBuilder.query(mDatabase, projection,selection, selectionArgs, null, null, sortOrder);
                break; 
			 case ITEM:
				 sqlBuilder.setTables(TABLE_ITEM);
	                c = sqlBuilder.query(mDatabase, projection,selection, selectionArgs, null, null, sortOrder);
	                break;
			 case ORDER_ITEM:
				 sqlBuilder.setTables(TABLE_ORDER_ITEM);
	                c = sqlBuilder.query(mDatabase, projection,selection, selectionArgs, null, null, sortOrder);
	                break;        
			 case ORDER:	
				 sqlBuilder.setTables(TABLE_ORDER);
	                c = sqlBuilder.query(mDatabase, projection,selection, selectionArgs, null, null, sortOrder);
	                break;       
			default:
	            throw new IllegalArgumentException("Unknown URI " + uri);
			}
	
			return c;
		}
		
		@Override
		public int update(Uri uri, ContentValues values, String selection ,String[] selectionArgs) {
			// TODO Auto-generated method stub
			final int match = sURIMatcher.match(uri);
			final Context context = getContext();
			final SQLiteDatabase db = getDatabase(context);
			int result = 0;
			try {
				
			} catch (Exception e)  {
				e.printStackTrace();
				switch(match){
				case CATEGORY: 
					result = db.update(TABLE_CATEGORY, values, selection, selectionArgs); 
					break;
				case DESCRIPTION:
				    result = db.update(TABLE_DESCRIPTION, values,selection, selectionArgs);
				    break;
				case ITEM:			  			        
				    result = db.update(TABLE_ITEM, values,selection, selectionArgs);
				    break;
				case ORDER_ITEM:
				     result = db.update(TABLE_ORDER_ITEM, values,selection, selectionArgs);
				     break;    
				case ORDER:
				    result = db.update(TABLE_ORDER, values,selection, selectionArgs);
				    break;
				}
	        	
	        }
	        
	        	getContext().getContentResolver().notifyChange(uri, null);
	        
			return result;
		}
	
	}
